/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package clip.net;

import L.L;
import clip.model.ClipboardSnapshot;
import clip.net.RMIApiInterface.Status;
import java.rmi.NotBoundException;
import java.rmi.RemoteException;
import java.rmi.registry.LocateRegistry;
import java.rmi.registry.Registry;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 *
 * @author admin
 */
public class RMIClient {

    private String host;
    private int port;
    private static Registry registry;
    private RMIApiInterface remoteAPI;

    public RMIApiInterface getRemoteApi() {
        return remoteAPI;
    }

    public RMIClient(String host, int port) throws RemoteException, NotBoundException {
        this.host=host;
        this.port=port;
        registry = LocateRegistry.getRegistry(host, port);
        remoteAPI = (RMIApiInterface) registry.lookup("RMIApi");
    }

    public boolean checkConnectionAlive() throws RemoteException {
        return remoteAPI.checkConnectionAlive();
    }

    public String getTestString() throws RemoteException {
        return remoteAPI.getTestString();
    }

    public ClipboardSnapshot getClipboardSnapshot() throws RemoteException {
        return remoteAPI.getClipboardSnapshot();
    }

  public void notifyStatusChanged(Status status) throws RemoteException {
    remoteAPI.notifyStatusChanged(status);
  }



    //testen
    public static void main(String[] args) throws Exception {
        RMIClient c = new RMIClient("localhost",1099);
        L.d(c.getRemoteApi().getTestString());
        L.d(c.getClipboardSnapshot().toString());
    }

    public String getHost() {
        return host;
    }

    public void setHost(String host) {
        this.host = host;
    }

    public int getPort() {
        return port;
    }

    public void setPort(int port) {
        this.port = port;
    }
}
